package patrol.mobile.com.mobilepatrol.activity.culvert;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.listener.OnRecyclerViewItemClickListener;
import com.dl7.recycler.listener.OnRecyclerViewItemLongClickListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.adapter.CulvertRegularListAdapter;
import patrol.mobile.com.mobilepatrol.bean.Hddqjcb;
import patrol.mobile.com.mobilepatrol.manager.HManager;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.widget.dialog.AppleDialog;

/**
 * Created by apple on 17/9/29.
 */

public class CulvertRegularCheckListActivity extends BaseActivity {
    @BindView(R.id.recycler)
    RecyclerView recyclerView;
    private BaseQuickAdapter<Hddqjcb> mAdapter;
    private List<Hddqjcb> mList = new ArrayList<>();
    private String hdcode;

    @Override
    protected int attachLayoutRes() {
        return R.layout.comment_list;
    }

    @Override
    public void setListener() {
        mAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent(CulvertRegularCheckListActivity.this,CulvertRegularCheckActivity.class);
                intent.putExtra("hdcode",hdcode);
                intent.putExtra("hddqjcid",mList.get(position).id);
                startActivity(intent);
                CommonUtil.openNewActivityAnim(CulvertRegularCheckListActivity.this,false);
            }
        });
        mAdapter.setOnItemLongClickListener(new OnRecyclerViewItemLongClickListener() {
            @Override
            public boolean onItemLongClick(View view, final int position) {

                final AppleDialog dialog = new AppleDialog(CulvertRegularCheckListActivity.this,R.style.Dialog,"确认删除？");
                dialog.show();
                dialog.setmListener(new AppleDialog.SureListener() {
                    @Override
                    public void onSure() {
                        HManager.delCulvertDQ(mList.get(position).id);
                        mList = HManager.getHDDQList(hdcode);
                        mAdapter.updateItems(mList);
                        dialog.dismiss();
                    }
                });


                return false;
            }
        });
    }
    @Override
    public void initView() {
        //super的重要性
        super.initView();
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new CulvertRegularListAdapter(CulvertRegularCheckListActivity.this, mList);
        recyclerView.setAdapter(mAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mList = HManager.getHDDQList(hdcode);
        mAdapter.updateItems(mList);
    }

    @Override
    public void initData() {
        super.initData();

        hdcode = getIntent().getStringExtra("hdcode");
        mList = HManager.getHDDQList(hdcode);
        mAdapter.updateItems(mList);

    }

    @Override
    public void initTitle() {
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                CommonUtil.exitActivityAndBackAnim(CulvertRegularCheckListActivity.this, true);
            }
        });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText("涵洞定期检查列表");



    }
}
